home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asmexam.arc / FREE.LST < prev    next >
Encoding:
File List  |  1983-11-17  |  15.2 KB  |  302 lines

  1.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-1
  2. 'FREE --- report free space on disk'
  3.  
  4.  
  5. 1                                 name     free
  6. 2                                 page     60,132
  7. 3                                 title    'FREE --- report free space on disk'
  8. 4                        
  9. 5                        ;FREE --- a utility to report free space on
  10. 6                        ;        the default or selected disk drive.
  11. 7                        ;
  12. 8                        ;Requires PC-DOS or MS-DOS 2.0
  13. 9                        ;
  14. 10                        ;Used in the form:
  15. 11                        ;A>FREE [unit:]
  16. 12                        ;(item in square brackets is optional)
  17. 13                        ;
  18. 14                        ;version 1.0 July 1, 1984
  19. 15                        ;Copyright (c) 1984 by Ray Duncan
  20. 16                        ;May be freely reproduced for non-commercial use.
  21. 17                        
  22. 18     = 000D                   cr       equ            0dh                 ;ASCII carriage return
  23. 19     = 000A                   lf       equ            0ah                 ;ASCII line feed
  24. 20     = 0020                   blank    equ            20h                 ;ASCII space code
  25. 21     = 0024                   eom      equ            '$'                 ;end of string marker
  26. 22                        
  27. 23                        
  28. 24                        ;Here we define a dummy segment containing lavbels
  29. 25                        ;for thedefault fiel control black and the command tail buffer,
  30. 26                        ;so that the main program can access those locations.
  31. 27                        ;
  32. 28     0000                   psp      segment para public 'PSP'
  33. 29                        
  34. 30     005C                            org            05ch
  35. 31     005C                   fcb      label          byte                ;default file control block
  36. 32                        
  37. 33     0080                            org            080h
  38. 34     0080                   command  label          byte                ;default command buffer
  39. 35                        
  40. 36     0080                   psp      ends
  41. 37                        
  42. 38     0000                   cseg     segment para public'CODE'
  43. 39                        
  44. 40                                 assume cs:cseg,ds:psp,es:data,ss:stack
  45. 41                        
  46. 42     0000                   get_drive proc near                         ;get drive selection, if any,
  47. 43                                                                    ;otherwise obtain the identity
  48. 44                                                                    ;of the current disk drive.
  49. 45                                                                    ;Return drive (1=A,2=B,etc)in RL.
  50. 46                                                                    ;
  51. 47     0000  A0 005C R                  mov            al,fcb              ;Pick up the drive code, parsed
  52. 48                                                                    ;by DOS into the default file
  53. 49                                                                    ;control block.
  54. 50     0003  0A C0                       or             al,al               ;Is it the default?
  55. 51     0005  75 06                       jnz            get_drive1          ;no, use it
  56. 52     0007  B4 19                       mov            ah,19h              ;Yes, get the actual current
  57. 53     0009  CD 21                       int            21h                 ;drive from PC-DOS.
  58. 54     000B  FE C0                       inc            al                  ;Increment to match FCB code.
  59. 55     000D                   get_drive1:                                 ;Return drive code in RL.
  60.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-2
  61. 'FREE --- report free space on disk'
  62.  
  63.  
  64. 56     000D  C3                       ret
  65. 57     000E                   get_drive endp
  66. 58                        
  67. 59     000E                   free     proc           far                 ;entry point from PC-DOS
  68. 60     000E  1E                       push           ds                  ;Save OS:0000 for final
  69. 61     000F  33 C0                       xor            ax,ax               ;return to PC-DOS
  70. 62     0011  50                       push           ax
  71. 63     0012  B8  ---- R                  mov            ax,data             ;make our data segment
  72. 64     0015  8E C0                       mov            es,ax               ;addressable via ES register.
  73. 65     0017  B4 30                       mov            ah,30h              ;check version of PC-DOS.
  74. 66     0019  CD 21                       int            21h
  75. 67     001B  3C 02                       cmp            al,2
  76. 68     001D  73 0A                       jae            free1               ;proceed, DOS 2.0 or greater.
  77. 69     001F  BA 0048 R                  mov            dx,offset msg2      ;DOS 1.x -- print error message
  78. 70     0022  8C C0                       mov            ax,es               ;and exit. First fix up DS register
  79. 71     0024  8E D8                       mov            ds,ax               ;;so error message is addressable.
  80. 72     0026  EB 01 90                       jmp            free1
  81. 73                        
  82. 74     0029  E8 0000 R         free1:   call           get_drive           ;get drive selection into DL.
  83. 75     002C  06                       push           es                  ;copy ES to Ds for remainder
  84. 76     002D  1F                       pop            ds                  ;of the program...
  85. 77                                 assume         ds:data             ;and tell assembler about it.
  86. 78     002E  8A D0                       mov            dl,al
  87. 79     0030  04 40                       add            al,'A'-1            ;form drive letter from drive soce,
  88. 80     0032  A2 001F R                  mov            outputb,al          ;and put i into the ouput string.
  89. 81     0035  B4 36                       mov            ah,36h              ;nob call dos to get free disk space
  90. 82     0037  CD 21                       int            21h
  91. 83     0039  3D FFFF                       cmp            ax,-1               ;was drive invalid?
  92. 84     003C  74 13                       je             free3               ;yes, go print error message
  93. 85                                                                    ;drive was ok, so now registers are.
  94. 86                        
  95. 87                                                                    ;RX=number of sectors per cluser
  96. 88                                                                    ;BX=available clusters,
  97. 89                                                                    ;CX=number of bytes per sector,
  98. 90                                                                    ;DX=total clusters per drive.
  99. 91                                                                    ;calculate free space:
  100. 92     003E  F7 E1                       mul            cx                  ;sectors per cluster * bytes/sector
  101. 93                                                                    ;(we assume no overflow into DX
  102. 94     0040  F7 E3                       mul            bx                  ;then* available clusers
  103. 95     0042  BE 000B R                  mov            si,offset (outputa+9)
  104. 96     0045  B9 000A                       mov            cx,10               ;CX = 10, radix for conversion
  105. 97     0048  E8 0059 R                  call           bin_to_asc          ;convert free space value to ASCII,
  106. 98     004B  BA 0000 R                  mov            dx,offset output
  107. 99     004E  EB 04 90                       jmp            free4               ;and print it out.
  108. 100                        
  109. 101     0051  BA 0024 R         free3:   mov            dx,offset msg1      ;illegal drive, print error
  110. 102                        
  111. 103     0054  B4 09              free4:   mov            ah,9                ;prin the string whose address
  112. 104     0056  CD 21                       int            21h                 ;is in DX.
  113. 105     0058  CB                       ret                                ;then return to DOS.
  114. 106                        
  115. 107     0059                   free   endp
  116. 108                        
  117. 109                        ;Convert 32 bit binary value to ASCII string.
  118. 110                        ;
  119.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-3
  120. 'FREE --- report free space on disk'
  121.  
  122.  
  123. 111                        ;Call with DX:AX = signed 32 but value
  124. 112                        ;        CX  =          radix
  125. 113                        ;        SI  =          last byte of area to store resulting string
  126. 114                        ;                       (make sure enough room is available to store
  127. 115                        ;                       the string in the radix you have selected.)
  128. 116                        ;
  129. 117                        ;Destroys RX,BX,CX,DX, and SI.
  130. 118                        ;
  131. 119     0059                   bin_to_asc proc near                        ;convert DX:AX to ASCII.
  132. 120                                                                    ;force storage of at least 1 digit.
  133. 121     0059  C6 04 30                       mov            byte ptr [si],'0'
  134. 122     005C  0B D2                       or             dx,dx               ;test sign of 32 bit value,
  135. 123     005E  9C                       pushf                              ;and save sign on stack.
  136. 124     005F  79 0A                       jns            bin1                ;jump if it was positive.
  137. 125     0061  F7 D2                       not            dx                  ;it was negative, take 2's complemen
  138. 126                        
  139. 127     0063  F7 D0                       not            ax                  ;of the value.
  140. 128     0065  05 0001                       add            ax,1
  141. 129     0068  83 D2 00                       adc            dx,0
  142. 130     006B                   bin1:                                       ;divide the 32 bit balue by the radi
  143. 131                        
  144. 132                                                                    ;to extract the next digit for the
  145. 133                                                                    ;forming string.
  146. 134     006B  8B D8                       mov            bx,ax               ;is the value zero yet?
  147. 135     006D  0B DA                       or             bx,dx
  148. 136     006F  74 13                       jz             bin3                ;yes, we are done converting.
  149. 137     0071  E8 008B R                  call           divide              ;no, divide by radix.
  150. 138     0074  80 C3 30                       add            bl,'0'              ;convert the remainder to an ASCII
  151. 139     0077  80 FB 39                       cmp            bl,'9'              ;we might be converting to hex ASCII
  152. 140                        
  153. 141     007A  7E 03                       jle            bin2                ;jump if in range 0-9,
  154. 142     007C  80 C3 07                       add            bl,'A'-'9'-1        ;correct it if in range A-F.
  155. 143     007F  88 1C              bin2:    mov            [si],bl             ;store this character into string.
  156. 144                                                                    ;to extract the next digit for the
  157. 145                                                                    ;forming string.
  158. 146     0081  4E                       dec            si                  ;back up throught string,
  159. 147     0082  EB E7                       jmp            bin1                ;and so it again.
  160. 148     0084                   bin3:                                       ;restore sign flag,
  161. 149     0084  9D                       popf                               ;was original value negative?
  162. 150     0085  79 03                       jns            bin4                ;no, jump
  163. 151                                                                    ;yes, store sign into ouput string.
  164. 152     0087  C6 04 2D                       mov            byte ptr[si],'-'
  165. 153     008A  C3              bin4:    ret                                ;back to caller.
  166. 154     008B                   bin_to_asc endp
  167. 155                        
  168. 156                        
  169. 157                        ;General purpose 32 bit by 16 bit unsigned divide.
  170. 158                        ;This must be used instead of the plain machine unsigned divide
  171. 159                        ;for cases where the quotient may overflow 16 bits (for example,
  172. 160                        ;dividing 100,000 by 2).  If called with a zero divisor, this
  173. 161                        ;routine returns the dividend unchanged and gives no warning.
  174. 162                        ;
  175. 163                        ;Call with     DX:AX = 32 bit dividend
  176. 164                        ;              CX    = divisor
  177. 165                        ;
  178.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-4
  179. 'FREE --- report free space on disk'
  180.  
  181.  
  182. 166                        ;Returns        DX:AX = quotient
  183. 167                        ;              BX = remainder
  184. 168                        ;              CX = divisor (unchanged)
  185. 169                        ;
  186. 170                        
  187. 171     008B                   divide   proc           near                ;Divide DX:AX by CX
  188. 172     008B  E3 0E                       jcxz           div1                ;exit if divide by zero
  189. 173     008D  50                       push           ax                  ;0:dividend_upper/divisor
  190. 174     008E  8B C2                       mov            ax,dx
  191. 175     0090  33 D2                       xor            dx,dx
  192. 176     0092  F7 F1                       div            cx
  193. 177     0094  8B D8                       mov            bx,ax               ;BX = quotient1
  194. 178     0096  58                       pop            ax                  ;remainder1:dividend_lower.divisor
  195. 179     0097  F7 F1                       div            cx
  196. 180     0099  87 DA                       xchg           bx,dx               ;DX:RX = quotient1:quotient2
  197. 181     009B  C3              div1:    ret                                ;BX = remainder2
  198. 182     009C                   divide   endp
  199. 183     009C                   cseg     ends
  200. 184                        
  201. 185                        
  202. 186     0000                   data     segment para public 'DATA'
  203. 187                        
  204. 188     0000  0D 0A              output   db      cr,lf
  205. 189     0002     0A [              outputa  db      10 dup(blank)
  206. 190                    20         
  207. 191                        ]         
  208. 192                        
  209. 193                        
  210. 194                        
  211. 195     000C  62 79 74 65 73 20             db      'bytes free on drive'
  212. 196           66 72 65 65 20 6F    
  213. 197           6E 20 64 72 69 76    
  214. 198           65              
  215. 199                        
  216. 200                        
  217. 201     001F  78 3A 0D 0A 24         outputb  db      'x:',cr,lf,eom
  218. 202                        
  219. 203     0024  0D 0A              msg1     db      cr,lf
  220. 204     0026  54 68 61 74 20 64             db      'That disk drive does not exist.'
  221. 205           69 73 6B 20 64 72    
  222. 206           69 76 65 20 64 6F    
  223. 207           65 73 20 6E 6F 74    
  224. 208           20 65 78 69 73 74    
  225. 209           2E              
  226. 210                        
  227. 211                        
  228. 212     0045  0D 0A 24                       db      cr,lf,eom
  229. 213                        
  230. 214     0048  0D 0A              msg2     db      cr,lf
  231. 215     004A  52 65 71 75 69 72             db      'Requires DOS version 2 or greater.'
  232. 216           65 73 20 44 4F 53    
  233. 217           20 76 65 72 73 69    
  234. 218           6F 6E 20 32 20 6F    
  235. 219           72 20 67 72 65 61    
  236. 220           74 65 72 2E         
  237.  The Microsoft MACRO Assembler             11-17-83        PAGE    1-5
  238. 'FREE --- report free space on disk'
  239.  
  240.  
  241. 221                        
  242. 222                        
  243. 223                        
  244. 224     006C  0D 0A 24                       db      cr,lf,eom
  245. 225     006F                   data     ends
  246. 226                        
  247. 227     0000                   stack    segment para stack 'STACK'
  248. 228     0000     40 [                       db      64 dup (?)
  249. 229                    ??         
  250. 230                        ]         
  251. 231                        
  252. 232                        
  253. 233     0040                   stack    ends
  254. 234                        
  255. 235                                 end free
  256.  
  257.  The Microsoft MACRO Assembler             11-17-83        PAGE    Symbols-1
  258. 'FREE --- report free space on disk'
  259.  
  260.  
  261. Segments and groups:
  262.  
  263.          N a m e              Size    align    combine    class
  264.  
  265. CSEG . . . . . . . . . . . . . .    009C    PARA      PUBLIC    'CODE'
  266. DATA . . . . . . . . . . . . . .    006F    PARA      PUBLIC    'DATA'
  267. PSP. . . . . . . . . . . . . . .    0080    PARA      PUBLIC    'PSP'
  268. STACK. . . . . . . . . . . . . .    0040    PARA      STACK     'STACK'
  269.  
  270. Symbols:            
  271.  
  272.          N a m e              Type    Value    Attr         
  273.  
  274. BIN1 . . . . . . . . . . . . . .    L NEAR     006B    CSEG
  275. BIN2 . . . . . . . . . . . . . .    L NEAR     007F    CSEG
  276. BIN3 . . . . . . . . . . . . . .    L NEAR     0084    CSEG
  277. BIN4 . . . . . . . . . . . . . .    L NEAR     008A    CSEG
  278. BIN_TO_ASC . . . . . . . . . . .    N PROC    0059    CSEG    Length =0032
  279. BLANK. . . . . . . . . . . . . .    Number    0020    
  280. COMMAND. . . . . . . . . . . . .    L BYTE     0080    PSP
  281. CR . . . . . . . . . . . . . . .    Number    000D    
  282. DIV1 . . . . . . . . . . . . . .    L NEAR     009B    CSEG
  283. DIVIDE . . . . . . . . . . . . .    N PROC    008B    CSEG    Length =0011
  284. EOM. . . . . . . . . . . . . . .    Number    0024    
  285. FCB. . . . . . . . . . . . . . .    L BYTE     005C    PSP
  286. FREE . . . . . . . . . . . . . .    F PROC    000E    CSEG    Length =004B
  287. FREE1. . . . . . . . . . . . . .    L NEAR     0029    CSEG
  288. FREE3. . . . . . . . . . . . . .    L NEAR     0051    CSEG
  289. FREE4. . . . . . . . . . . . . .    L NEAR     0054    CSEG
  290. GET_DRIVE. . . . . . . . . . . .    N PROC    0000    CSEG    Length =000E
  291. GET_DRIVE1 . . . . . . . . . . .    L NEAR     000D    CSEG
  292. LF . . . . . . . . . . . . . . .    Number    000A    
  293. MSG1 . . . . . . . . . . . . . .    L BYTE     0024    DATA
  294. MSG2 . . . . . . . . . . . . . .    L BYTE     0048    DATA
  295. OUTPUT . . . . . . . . . . . . .    L BYTE     0000    DATA
  296. OUTPUTA. . . . . . . . . . . . .    L BYTE     0002    DATA    Length =000A
  297. OUTPUTB. . . . . . . . . . . . .    L BYTE     001F    DATA
  298.  
  299. Warning Severe
  300. Errors    Errors 
  301. 0    0
  302.